﻿namespace EyeOpen.TimeAssistant.Client.Wcf
{
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Channels;

    public class AsynchronousAuthenticationServiceProxy : ClientBase<IAuthenticationService>, IAuthenticationService
    {
        public AsynchronousAuthenticationServiceProxy()
        {
        }

        public AsynchronousAuthenticationServiceProxy(string endpointConfigurationName) :
            base(endpointConfigurationName)
        {
        }

        public AsynchronousAuthenticationServiceProxy(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }

        public AsynchronousAuthenticationServiceProxy(string endpointConfigurationName, EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }

        public AsynchronousAuthenticationServiceProxy(Binding binding, EndpointAddress remoteAddress) :
            base(binding, remoteAddress)
        {
        }

        public event EventHandler<AuthenticateUserCompletedEventArgs> AuthenticateUserCompleted;

        public bool AuthenticateUser(string username, string password)
        {
            var asyncResult = BeginAuthenticateUser(username, password, null, null);

            return EndAuthenticateUser(asyncResult);
        }

        public IAsyncResult BeginAuthenticateUser(string username, string password, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginAuthenticateUser(username, password, callback, asyncState);
        }

        public bool EndAuthenticateUser(IAsyncResult result)
        {
            return Channel.EndAuthenticateUser(result);
        }
    }
}
